public class Distance {
	private float lengthInMetres;
	
	public Distance(float length){
		lengthInMetres = length;
	}
	
	public double getLength(){
		return lengthInMetres;
	}
	
	public void setLength(float length){
		lengthInMetres = length;
	}
	
	public void printLengthInMetres(){
		
		System.out.println(lengthInMetres+" metres in metres is: ");
		
		if(lengthInMetres==1){
			System.out.println("1 metre");
		}
		else{
			System.out.println(lengthInMetres + " metres");
		}
	}
	
	public void printLengthInImeprial(){
		
		//Declaring the variables
        int yards=0,feet=0,inches=0;
        int yardsFeetInches[] = calculateImperial();
        yards=yardsFeetInches[0];
        feet=yardsFeetInches[1];
        inches=yardsFeetInches[2];
        //------------------------
       
        System.out.println(lengthInMetres+" metres in imperial measures is: ");
        
        //different ways of printing the yards,feet and inches
        //depending on their value
        if(yards==0){
            if(feet==0){
                if(inches==1){
                    System.out.println("1 inch");
                }
                else{
                    System.out.println(inches + " inches");
                }
            }
            else
                if(feet==1){
                    if(inches==0){
                        System.out.println("1 foot");
                    }
                    else 
                        if(inches==1){
                            System.out.println("1 foot and 1 inch");
                        }
                        else{
                            System.out.println("1 foot " + inches + " inches");
                        }
                }
                else{
                    if(inches==0){
                        System.out.println(feet + " feet");
                    }
                    else
                        if(inches==1){
                            System.out.println(feet + " feet and 1 inch");
                        }
                        else{
                            System.out.println(feet + " feet and " + inches + " inches");
                        }
                }
        }
        else
            if(yards==1){
                if(feet==0){
                    if(inches==0){
                        System.out.println("1 yard");
                    }
                    else
                        if(inches==1){
                            System.out.println("1 yard and 1 inch");
                        }
                        else{
                            System.out.println("1 yard and " + inches + " inches");
                        }
                }
                else
                    if(feet==1){
                        if(inches==0){
                            System.out.println("1 yard and 1 foot");
                        }
                        else
                            if(inches==1){
                                System.out.println("1 yard, 1 foot and 1 inch");
                            }
                            else{
                                System.out.println("1 yard, 1 foot and " + inches + " inches");
                            }
                    }
                    else{
                        if(inches==0){
                            System.out.println("1 yard and "+feet+" feet");
                        }
                        else
                            if(inches==1){
                                System.out.println("1 yard, "+feet+" feet and 1 inch");
                            }
                            else{
                                System.out.println("1 yard, "+feet+" feet and "+inches+" inches");
                            }
                    }
            }
            else{
                if(feet==0){
                    if(inches==0){
                        System.out.println(yards+" yards");
                    }
                    else
                        if(inches==1){
                            System.out.println(yards+" yards and 1 inch");
                        }
                        else{
                            System.out.println(yards+" yards and "+inches+" inches");
                        }
                }
                else
                    if(feet==1){
                        if(inches==0){
                            System.out.println(yards+" yards and 1 foot");
                        }
                        else
                            if(inches==1){
                                System.out.println(yards+" yards, 1 foot and 1 inch");
                            }
                            else{
                                System.out.println(yards+" yards, 1 foot and "+inches+" inches");
                            }
                    }
                    else{
                        if(inches==0){
                            System.out.println(yards+" yards and "+feet+" feet");
                        }
                        else
                            if(inches==1){
                                System.out.println(yards+" yards, "+feet+" feet and 1 inch");
                            }
                            else{
                                System.out.println(yards+" yards, "+feet+" feet and "+inches+" inches");
                            }
                    }
            }
    }
    
    public int[] calculateImperial(){
    	
    	//Declaring he variables
        float inchesInMetre=39.3700787f;
        int[] yardsFeetInches = new int[3];
        int remainingInches = java.lang.Math.round(inchesInMetre*lengthInMetres);
        //-----------------------
        
        //in the array the 0 element is for the yards
        yardsFeetInches[0]=remainingInches/36;
        remainingInches=remainingInches-yardsFeetInches[0]*36;
        
        //in the array the 1st element is for the feet
        yardsFeetInches[1]=remainingInches/12;
        remainingInches=remainingInches-yardsFeetInches[1]*12;
        
        //in the array the 2nd element is for the inches
        yardsFeetInches[2]=remainingInches;
        
        return yardsFeetInches;
    }
    
    public void printDistanceFromUserChoice(){
		
		System.out.println("If you want the distance to be printed in metres enter 1, " +
				"if you want it to be printed in imperial measures enter 2: ");
		
		int userChoiceOfPrint = EasyIn.getInt();
		
		while(userChoiceOfPrint!=1 && userChoiceOfPrint!=2){
			System.out.println("You entered an invalid number. Please enter 1 or 2: ");
			userChoiceOfPrint = EasyIn.getInt();
		}
		
		if(userChoiceOfPrint==1){
			printLengthInMetres();
		}
		else{
			printLengthInImeprial();
		}
    }
}
